package encoding

import (
	"github.com/xxtea/xxtea-go/xxtea"
	"strconv"
	"time"
)

type PlatformToken struct {
	Timestamp int64
}

// 平台和游戏服务器交互 加密
func EncodePlatform(key string) (token string) {
	nowUnix := strconv.FormatInt(time.Now().Unix(), 10)
	res := xxtea.Encrypt([]byte(nowUnix), []byte(key))
	token = string(res)
	return
}

// 平台和游戏服务器交互 解密
func DecodePlatform(token string, key string) (timestamp int64) {
	data := xxtea.Decrypt([]byte(token), []byte(key))
	timestamp, _ = strconv.ParseInt(string(data), 10, 64)
	return
}
